package com.hqhy.like.stock.controller;

import com.hqhy.like.common.web.JsonResult;
import com.hqhy.like.stock.pojo.entity.Table;
import com.hqhy.like.stock.service.ITableService;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 桌台管理 的控制层
 */
@Slf4j
@RestController
@Validated
@RequestMapping("/table")
public class TableController {

    @Autowired
    private ITableService tableService;

    @PostMapping("/insert")
    public JsonResult addNew(@Valid Table table){
        log.debug("开始处理【添加桌台】的请求，参数：{}", table);
        tableService.addNew(table);
        return JsonResult.ok();
    }
    //    @PreAuthorize("hasAuthority('/account/user/delete')")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable @Range(min = 1,message = "请提交合法的用户ID值!") Long id){
        log.debug("开始处理【根据ID删除用户】的请求，参数：{}", id);
        tableService.delete(id);
        return JsonResult.ok();
    }

    /**
     * 查询桌台列表
     */
    @GetMapping("/list")
    public JsonResult list() {
        log.debug("开始处理【查询桌台列表】的请求");
        List<Table> pageData = tableService.list();
        return JsonResult.ok(pageData);
    }
    //    @PreAuthorize("hasAuthority('/account/user/enable')")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult setEnable(@PathVariable @Range(min = 1, message = "请提交合法的用户ID值！") Long id){
        log.debug("开始处理【启用桌台】的请求，参数：{}", id);
        tableService.setEnable(id);
        return JsonResult.ok();
    }

    //    @PreAuthorize("hasAuthority('/account/user/disable')")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult setDisable(@PathVariable @Range(min = 1, message = "请提交合法的用户ID值！") Long id){
        log.debug("开始处理【禁用桌台】的请求，参数：{}", id);
        tableService.setDisable(id);
        return JsonResult.ok();
    }
}
